/** 
  *@CopyRight(c)2009 company Co.Ltd. 
  *@All right reserved.
  *@module name: App.BaseInfoManage.TradeDaysManage
  *@description:
  *
  *@author: lugj
  *@version: 1.0
  *@date: 2009/06/21
  *@last date: 2009/06/21
  *@history:
    1.
    2.
  *@bugs:
    1. 
    2. 
  *
*/ 

Ext.namespace("App.BaseInfoManage");

//TradeDaysManage Class
//config: {id: , }
App.BaseInfoManage.TradeDaysManage = function(config){

	//generating the global unique id.
	this.config = config;

	this.MODULE_ID = (typeof(this.config) == 'undefined') ? null : this.config.id;

	this.MODULE_ID = (this.MODULE_ID == null) ? App.Base.Common.func.getSystemDateTimeMark() : this.MODULE_ID;
	
	this.MODULE_ID = 'TRADEDAYSMGR' + this.MODULE_ID;

	this.OpCmd = App.Base.common.param.OP_CMD_NONE;

	this.loadMask = new Ext.LoadMask(Ext.getBody(), {msg: "系统正在加载交易日数据，请稍候..."});

    this.store = new Ext.data.Store({
		id: 'store' + this.MODULE_ID,
        proxy: new Ext.data.HttpProxy({url: App.Base.common.param.TRADESMGR_TRADEDAY_OPERATION_DATAURL}),
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
        }, [
            {name: 'Sat'},
            {name: 'Sun'},
            {name: 'Mon'},
            {name: 'tues'},
            {name: 'Wed'},
            {name: 'Thurs'},
            {name: 'Friday'}
        ]),
		listeners: {
			beforeload: function(store, options){
				//options.params.searchKey = this.searchKey;
				this.loadMask.show();
			},
			load: function(store, records, options) {
				this.loadMask.hide();
			},
			scope: this
		}
    });
    
    this.grid = new Ext.grid.GridPanel({
		id: 'grid' + this.MODULE_ID,
    	border: false,
    	frame: true,
        stripeRows: true,
        //loadMask: {msg: '系统正在加载交易日数据，请稍候...'},
        autoExpandColumn: 'Friday',
        enableColumnMove: false,
		enableColumnResize: false,
		enableHdMenu: false,
        autoDestroy: true,
        //title: '年月日',

		sm: new Ext.grid.CellSelectionModel({
			listeners: {
				beforecellselect: function(selectionModel, rowIndex, colIndex){
					if (this.grid.getStore().getAt(rowIndex).get(this.grid.getColumnModel().getDataIndex(colIndex)).trim().length == 0)
					{
						return false;
					}
					return true;
				},
				scope: this
			}
		}),

        cm: new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
            {header: '星期六', dataIndex: 'Sat', width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return "<font color='green'>" + value + "</font>";
				}
			},
            {header: '星期日', dataIndex: 'Sun' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return "<font color='green'>" + value + "</font>";
				}
			},
            {header: '星期一', dataIndex: 'Mon' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return value;
				}
			},
            {header: '星期二', dataIndex: 'tues' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return value;
				}
			},
            {header: '星期三', dataIndex: 'Wed' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return value;
				}
			},
            {header: '星期四', dataIndex: 'Thurs' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return value;
				}
			},
            {header: '星期五', dataIndex: 'Friday' , width: 64, renderer: function(value){
					if (value.trim().length > 10)
					{
						return "<font color='red'>" + value + "</font>";
					}
					return value;
				}
			}
        ]),

        store: this.store,

        //tbar: new Ext.Toolbar(['']),

        viewConfig: {
            forceFit: true,
            enableRowBody: true,
            getRowClass: function(record, rowIndex, p, ds) {
                var cls = 'white-row';
                switch (rowIndex%2) {
                    case 1:
                        cls = 'red-row'
                        break;
                }
                return cls;
            }
        }
    });

    this.gridContextMenu = new Ext.menu.Menu({
        id: 'gridContextMenu' + this.MODULE_ID,
        items: [{
            id: 'mnuSet' + this.MODULE_ID,
            text: '设置交易日',
            iconCls: 'x-menu-personinfolist-add'
        }, '-', {
            id: 'mnuCancel' + this.MODULE_ID,
            text: '取消交易日',
            iconCls: 'x-menu-personinfolist-delete'
        }]
        
    });
    
    this.gridContextMenu.on('click', function(menu, menuItem, e){
        this.gridContextMenu.hide();
        
        var menuItemId = menuItem.getId();

		var cell = this.grid.getSelectionModel().getSelectedCell(); 
		var colName = this.grid.getColumnModel().getDataIndex(cell[1]);   
		var celldata = this.grid.getStore().getAt(cell[0]).get(colName);
				        
        switch(menuItemId)
        {
            case 'mnuSet' + this.MODULE_ID:
				alert(celldata);
				break;
            case 'mnuCancel' + this.MODULE_ID:

				break;
            default:               
				break;
        }
               
    }, this);
        
	this.XY = null;

	this.grid.on('cellclick', function(grid, rowIndex, columnIndex, e){
		this.XY = e.getXY();
	}, this);    
	
	this.grid.on('cellcontextmenu', function(grid, rowIndex, cellIndex, e){
        e.preventDefault();
        
		if (grid.getSelectionModel().hasSelection())
		{
			this.gridContextMenu.showAt(this.XY);
		}
    }, this);

	this.store.load({params:{start: 0, limit: App.Base.common.param.GRID_PAGE_SIZE_15}});

    this.formPanel = new Ext.FormPanel({
		id: 'fp' + this.MODULE_ID,
		autoDestroy: true,
		border: false,

		layout: 'border',
		items: [{
			region:'west',
			id: 'fpW' + this.MODULE_ID,
			width: 640,
			minWidth: 580,

			//frame: true,
			border: false,
			autoScroll: true,

			split : true,
			collapsible : true,
			bodyStyle:'padding:5px 5px 5px 0',

			bbar: new Ext.Toolbar({
				id: 'bbar01' + this.MODULE_ID,
				border: false,

				items : ['-',
					new Ext.Button({
						id: 'btnAdd' + this.MODULE_ID,
						text: '<font color="blue">新增交易日</font>',
						iconCls: 'x-menu-personinfolist-add',
						handler: function(){
							

						},
						scope: this
					}), '-',
					new Ext.Button({
						id: 'btnDel' + this.MODULE_ID,
						text: '<font color="blue">删除交易日</font>',
						iconCls: 'x-menu-personinfolist-delete',
						handler: function(){
							

						},
						scope: this
					}), '-',
					new Ext.Button({
						id: 'btnReset' + this.MODULE_ID,
						text: '<font color="blue">重置</font>',
						iconCls: 'x-menu-systemmenusmanage-rset',
						handler: function(){
							

						},
						scope: this
					})
				]
			}),

			layout: 'border',
			items: [{
				region:'north',
				id: 'fpWN' + this.MODULE_ID,
				title: '交易日',
				height: 260,
				border: false,
				autoScroll: true,
				split : true,
				collapsible : true,

				bbar: new Ext.Toolbar({
					id: 'bbar02' + this.MODULE_ID,
					border: false,

					items : ['->', '-', new Ext.form.DateField({
							id: 'currdt' + this.MODULE_ID,
							format: 'Y-m-d',
							fieldLabel: '<font color="blue">查询日期</font>',
							width: 128
						}), new Ext.Button({
							id: 'btnLookup' + this.MODULE_ID,
							text: '<font color="blue">查询</font>',
							iconCls: 'x-button-systemmanage-search',
							handler: function(){
								

							},
							scope: this
						}), '-',
						new Ext.Button({
							id: 'btnUpMonth' + this.MODULE_ID,
							text: '<font color="blue">上月</font>',
							iconCls: 'x-button-systemmanage-arrowleft01',
							handler: function(){
								

							},
							scope: this
						}),
						new Ext.Button({
							id: 'btnNextMonth' + this.MODULE_ID,
							text: '<font color="blue">下月</font>',
							iconCls: 'x-button-systemmanage-arrowright01',
							handler: function(){
								

							},
							scope: this
						}), '-' ,
						new Ext.Button({
							id: 'btnRefresh' + this.MODULE_ID,
							text: '<font color="blue">刷新</font>',
							iconCls: 'x-menu-mainframe-refresh',
							handler: function(){
								

							},
							scope: this
						}), '-'
					]
				}),

				layout: 'fit',
				items: [this.grid]
			}, {
				region:'center',
				id: 'fpWC' + this.MODULE_ID,
				labelAlign: 'left',
				labelWidth: 86,
				frame: true,
				border: false,
				autoScroll: true,
				bodyStyle:'padding:5px 5px 5px 0',
				layout: 'form',
				items: [
					new Ext.form.ComboBox({
						id: 'weekend' + this.MODULE_ID,
						fieldLabel: '<font color="blue">日期周末类型</font>',
						width : 128,
						store: new Ext.data.SimpleStore({
							fields: ['value', 'text'],
							data: [
								['0', '不包括周末'],
								['1', '包括周末']
							]
						}),
						value: 0,	
						mode: 'local',
						editable: false,
						allowBlank: false,
						triggerAction: 'all',
						valueField: 'value',
						displayField: 'text'
					}),
					new Ext.form.DateField({
						id: 'startdt' + this.MODULE_ID,
						format: 'Y-m-d',
						fieldLabel: '<font color="blue">起始日期</font>',
						width: 128
					}),
					new Ext.form.DateField({
						id: 'enddt' + this.MODULE_ID,
						format: 'Y-m-d',
						fieldLabel: '<font color="blue">结束日期</font>',
						width: 128
					})
				]
			}]
		}, {
			region:'center',
			id: 'fpC' + this.MODULE_ID,
			border: false,
			autoScroll: true,
			frame: true,
			layout: 'fit',
			items: [
			]

		}]
	});

	this.formPanel.doLayout();

	//defined methods.
    if((typeof App.BaseInfoManage.TradeDaysManage.SIMULATE_SHARED_METHODS_FLAG) == "undefined")
    {
        App.BaseInfoManage.TradeDaysManage.SIMULATE_SHARED_METHODS_FLAG = true;   

        App.BaseInfoManage.TradeDaysManage.prototype.getMainPanel = function(){   
            return this.formPanel;  
        };
 
        //simulating the class's constructor().
        var __ctor = function(){
            //alert('called __constructor() ok.');
        }();

    }
}